"""ShopOL URL Configuration

The `urlpatterns` list routes URLs to views. For more information please see:
    https://docs.djangoproject.com/en/1.11/topics/http/urls/
Examples:
Function views
    1. Add an import:  from my_app import views
    2. Add a URL to urlpatterns:  url(r'^$', views.home, name='home')
Class-based views
    1. Add an import:  from other_app.views import Home
    2. Add a URL to urlpatterns:  url(r'^$', Home.as_view(), name='home')
Including another URLconf
    1. Import the include() function: from django.conf.urls import url, include
    2. Add a URL to urlpatterns:  url(r'^blog/', include('blog.urls'))
"""
from django.conf.urls import url, include
from django.contrib import admin
from django.views.generic import TemplateView

import xadmin
from rest_framework_jwt.views import obtain_jwt_token
from rest_framework.documentation import include_docs_urls
from rest_framework.routers import DefaultRouter
from ShopOL.settings import MEDIA_ROOT
from django.views.static import serve
from goods.views import GoodsListViewSet, GoodsCategoryViewSet, HotSearchViewSet, BannerViewSet, IndexCategoryViewSet
from users.views import SmsCodeViewSet, UserViewSet
from user_operation.views import UserFavViewSet, UserLeavingMessageViewSet, AddressViewSet
from trade.views import ShoppingCartViewSet, OrderInfoViewSet, AlipayView

router = DefaultRouter()
# 商品
router.register(r'goods', GoodsListViewSet, base_name='goods')
# 商品类目
router.register(r'category', GoodsCategoryViewSet, base_name='category')
# 短信验证码
router.register(r'codes', SmsCodeViewSet, base_name='codes')
# 用户注册
router.register(r'users', UserViewSet, base_name='users')
# 热词搜索
router.register(r'hotsearchs', HotSearchViewSet, base_name="hotsearchs")
# 用户收藏
router.register(r'userfavs', UserFavViewSet, base_name='userfavs')
# 用户留言
router.register(r'usermsg', UserLeavingMessageViewSet, base_name='usermsg')
# 收货地址
router.register(r'address', AddressViewSet, base_name='address')
# 购物车
router.register(r'shopcarts', ShoppingCartViewSet, base_name='shopcarts')
# 订单管理
router.register(r'orders', OrderInfoViewSet, base_name='orders')
# 轮播图
router.register(r'banners', BannerViewSet, base_name='banners')
# 首页商品系列数据
router.register(r'indexgoods', IndexCategoryViewSet, base_name='indexgoods')

urlpatterns = [
    url(r'^admin/', admin.site.urls),
    url(r'^xadmin/', xadmin.site.urls),
    # 文件上传路径
    url(r'^media/(?P<path>.*)$', serve, {"document_root": MEDIA_ROOT}),
    url(r'^api-auth/', include('rest_framework.urls', namespace='rest_framework')),
    # ueditor url
    url(r'^ueditor/', include('DjangoUeditor.urls')),
    url(r'^docs/', include_docs_urls(title='B')),
    # url(r'^good/', GoodsListView.as_view()),
    url(r'^api/', include(router.urls)),
    # django代理vue
    url(r'^$', TemplateView.as_view(template_name="index.html"), name="index"),
    # drf 自带token认证接口
    # url(r'^api-token-auth/', views.obtain_auth_token),
    # jwt 认证接口
    url(r'^login/$', obtain_jwt_token),
    # alipay 回调接口
    url(r'^alipay/return/', AlipayView.as_view(), name='alipay'),
    # 第三方登陆接口
    url('', include('social_django.urls', namespace='social'))
]
